<script setup lang="ts">
//引入组合式API函数ref
import { ref, onMounted, reactive, nextTick } from 'vue';
import { reqHasTrademark } from '@/api/product/trademark';
//当前页码
let pageNo = ref<number>(1);
//每一页展示多少条数据
let limit = ref<number>(3);
//存储已有品牌数据总数
let total = ref<number>(0);
//存储已有品牌的数据
let trademarkArr = ref([]);
//获取已有品牌的接口封装为一个函数:在任何情况下向获取数据,调用次函数即可
const getHasTrademark = async (pager = 1) => {
  //当前页码
  pageNo.value = pager;
  let result: any = await reqHasTrademark(pageNo.value, limit.value);
  if (result.code == 200) {
    //存储已有品牌总个数
    total.value = result.data.total;
    trademarkArr.value = result.data.records;
  }
}
//组件挂载完毕钩子---发一次请求,获取第一页、一页三个已有品牌数据
onMounted(() => {
  getHasTrademark();
});
</script>
<template>
  <el-card class="app">
    <el-button type="primary" size="default" icon="Plus" @click="addTrademark"
      v-has="`btn.Trademark.add`">添加品牌</el-button>
    <el-table style="margin:10px 0px" border :data="trademarkArr">
      <el-table-column label="序号" width="80px" align="center" type="index"></el-table-column>
      <!-- table-column:默认展示数据用div -->
      <el-table-column label="品牌名称" prop="tmName">
      </el-table-column>
      <el-table-column label="品牌LOGO">
        <template #="{ row, $index }">
          <img :src="row.logoUrl" style="width:100px;height: 100px;">
        </template>
      </el-table-column>
      <el-table-column label="品牌操作">
        <template #="{ row, $index }">
          <el-button type="primary" size="small" icon="Edit" @click="updateTrademark(row)"></el-button>
          <el-popconfirm :title="`您确定要删除${row.tmName}?`" width="250px" icon="Delete" @confirm='removeTradeMark(row.id)'>
            <template #reference>
              <el-button type="primary" size="small" icon="Delete"></el-button>
            </template>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination @size-change="getHasTrademark" @current-change="getHasTrademark" :pager-count="9"
      v-model:current-page="pageNo" v-model:page-size="limit" :page-sizes="[3, 5, 7, 9]" :background="true"
      layout="prev, pager, next, jumper,->,sizes,total" :total="total" />
  </el-card>
</template>
<style lang="scss" scoped></style>